<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

class IgnoreNotice extends BatchAction
{
    protected $action;

    public function __construct($action = 5)
    {
        $this->action = $action;
    }

    public function script()
    {
        return <<<EOT

$('{$this->getElementClass()}').on('click', function() {
    $.confirm({
        title: '提示信息!',
        content: '确定要将所选待办忽略吗？忽略后不可恢复！！且不能进行数据录入，也不能生成对应的报表！请慎重操作！！！',
        buttons: {
            cancel: {
                text: "取消",
                btnClass: 'btn-primary',
                keys: ['esc'],
                action:function () {
                    $.pjax.reload('#pjax-container');
                }
            },
            ok: {
                text: "确定",
                btnClass: 'btn-primary',
                keys: ['enter'],
                action: function(){
                    $.ajax({
                        method: 'post',
                        url: '{$this->resource}/ignore_notice',
                        data: {
                            _token:LA.token,
                            ids: selectedRows(),
                            action: {$this->action}
                        },
                        success: function () {
                            $.pjax.reload('#pjax-container');
                            toastr.success('操作成功');
                            parent.location.reload();
                        }
                    });
                }
            }
        }
    });
});



EOT;

    }
}